<?php
/**
 * Created by PhpStorm.
 * User: Jason.Jiang
 * Date: 2015/9/18
 * Time: 14:35
 */
class Database
{
    private $link = '';

    public function __construct($configs)
    {
        $this->connection($configs);
    }

    public function connection($config)
    {
        $this->link = mysqli_connect($config['host'], $config['username'], $config['password'], $config['database']) or die('unknow database!');
    }

    public function getTables()
    {

        $sql = "SHOW tables";
        $result = mysqli_query($this->link, $sql);
        $data = array();
        while($all = $result->fetch_row())
        {
            $data[] = $all[0];
        }

        return $data;
    }

    public function getColumn($table)
    {

        $sql = "SELECT * FROM " . $table;

        $result = mysqli_query($this->link, $sql);
        $columns = $result->fetch_fields();
        if($columns)
        {
            foreach($columns as $col)
            {
                $data[] = $col->name;
            }
        }

        return $data;
    }


    public function close()
    {

    }
}